#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@author:zhengxin
@file: 031_sum_odd_even_numbers.py
@time: 2024/12/23  10:23
# @describe:
"""

"""
题目1：编写一个函数，输入n为偶数时，调用函数求1/2+1/4+...+1/n,当输入n为奇数时，调用函数1/1+1/3+...+1/n

"""
# 方式一
def sum_odd_even_numbers():
    n = 17
    fenum = range(2, n+1, 2) if n%2==0 else range(1, n+1, 2)
    s = sum(map(lambda x:1/x, fenum))
    print(s)



sum_odd_even_numbers()



# 方式二
def sum_odd_even_numbers_1():
    n = 17
    ls = sum([1/i for i in range(n ,0, -2)])
    print(ls)

sum_odd_even_numbers_1()





"""
题目2：找到年龄最大的人，并输出。
    person = {"li":18,"wang":50,"zhang":20,"sun":22}
    
"""
person = {"li": 18, "wang": 50, "zhang": 20, "sun": 22}
name, age = '', 0
for p in person.keys():
    if person.get(p) > age:
        name, age = p, person.get(p)
print(name, age)